package com.example.mine_platform.controller;

import com.example.mine_platform.commom.Result;
import com.example.mine_platform.pojo.dto.ProductionDTO;
import com.example.mine_platform.pojo.dto.ProductionNewDTO;
import com.example.mine_platform.pojo.vo.ProductionDetailVO;
import com.example.mine_platform.pojo.vo.ProductionVO;
import com.example.mine_platform.service.ProductionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class ProductionController {
    @Resource
    private ProductionService productionService;

    @GetMapping("/api/allProductions")
    public Result getAllProductions() {
        List<ProductionVO> productionVOList = productionService.getAllProduction();
        return Result.success(productionVOList);
    }

    @GetMapping("/api/production/{id}")
    public Result getProductionDetail(@PathVariable Integer id) {
        ProductionDetailVO productionDetailVO = productionService.getProductionDetail(id);
        return Result.success(productionDetailVO);
    }

    @PostMapping("/api/production")
    public Result insertNewProduction(@RequestBody ProductionNewDTO productionNewDTO) {
        Result result = productionService.insertNewProduction(productionNewDTO);
        return result;
    }

    @PutMapping("/api/production")
    public Result updateProduction(@RequestBody ProductionDTO productionDTO) {
        Result result = productionService.updateProduction(productionDTO);
        return result;
    }

    @DeleteMapping("/api/production/{id}")
    public Result deleteProduction(@PathVariable Integer id) {
        Result result = productionService.deleteProduction(id);
        return result;
    }
}
